package com.example.supernote.data.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.supernote.data.dao.FileEntityDao
import com.example.supernote.data.dao.TrashEntityDao
import com.example.supernote.data.entity.FileEntity
import com.example.supernote.data.entity.TrashEntity


@Database(entities = [FileEntity::class,TrashEntity::class], version = 2, exportSchema = false)
abstract class FileEntityDatabase : RoomDatabase() {
    abstract fun fileEntityDao(): FileEntityDao
    abstract fun trashEntityDao(): TrashEntityDao
    companion object {
        @Volatile
        private var Instance: FileEntityDatabase? = null

        fun getDatabase(context: Context): FileEntityDatabase {
            // if the Instance is not null, return it, otherwise create a new database instance.
            return Instance ?: synchronized(this) {
                Room.databaseBuilder(context, FileEntityDatabase::class.java, "file_entity_database")
                    .fallbackToDestructiveMigration()
                    .build()
                    .also { Instance = it }
            }
        }
    }
}